home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / Game Source / jam src / STTanker.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-03  |  4.9 KB  |  223 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: STTanker.c
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Sunday, January 3, 1993, 10:09
  6.      Created: Tuesday, February 5, 1991, 4:25
  7.  
  8.      Copyright © 1991-1993, Juri Munkki
  9. /*/
  10.  
  11. #include "VA.h"
  12. #include "STORM.h"
  13.  
  14. #define    MAXTANKERS        10
  15. #define    TANKERCOLOR        (ThisLevel.ftColor)
  16. #define    TANKERUPSPEED    (ThisLevel.ftSpeed)
  17.  
  18. typedef    struct
  19. {
  20.     int        tanktype;    /*    FlipTank, FuseTank, PulsTank        */
  21.     int        state;        /*    star=0, inactive=1, active=2        */
  22.     IFixed    level;
  23.     int        lane;
  24. }    Tanker;
  25.  
  26. enum    {    star, inactive, active    };
  27.  
  28. extern        Player    Hero;
  29. Tanker        *Tankers;
  30. int            ActiveTankers;
  31. int            ActiveTypes[TANKTYPES];
  32.  
  33. void    CreateSplitFlippers(int lane,int level);
  34.  
  35. void    DrawTanker(cx,cy,dx,dy,tanktype)
  36. int        cx,cy,dx,dy,tanktype;
  37. {
  38.     register    int    x1,y1,x2,y2;
  39.     
  40.     VA.color=ThisLevel.tk[tanktype].color;
  41.     x1= dx >> 1;
  42.     y1= dy >> 1;
  43.     x2= dx >> 2;
  44.     y2= dy >> 2;
  45.     VAMoveTo(cx,cy);
  46.     VALineTo(cx+x1+y1    ,cy+y1-x1);
  47.     VALineTo(cx+dx        ,cy+dy);
  48.     VALineTo(cx+x1-y1    ,cy+y1+x1);
  49.     VALineTo(cx            ,cy);
  50.     VALineTo(cx+x2        ,cy+y2);
  51.     VALineTo(cx+x1-y2    ,cy+y1+x2);
  52.     VALineTo(cx+dx-x2    ,cy+dy-y2);
  53.     VALineTo(cx+x1+y2    ,cy+y1-x2);
  54.     VALineTo(cx+x2        ,cy+y2);
  55.     VAMoveTo(cx+dx-x2    ,cy+dy-y2);
  56.     VALineTo(cx+dx        ,cy+dy);
  57. }
  58. /*
  59. >>    Create a newborn tanker. A tanker appears
  60. >>    as one of the center stars, so the lane or
  61. >>    vertex is decided when the star touches the
  62. >>    playfield. Some of this stuff could just as 
  63. >>    well be done at that time.
  64. */
  65. void    CreateNewTanker(tanktype)
  66. int        tanktype;
  67. {
  68.     register    Tanker        *thetank;
  69.  
  70.     if(ActiveTankers<MAXTANKERS)
  71.     {    thetank=Tankers;
  72.         while(thetank->state!=inactive)
  73.         {    thetank++;
  74.         }
  75.         thetank->tanktype=tanktype;
  76.         thetank->state=star;
  77.         thetank->lane=0;
  78.         thetank->level.f=0;
  79.         thetank->level.i=DEPTH;
  80.     
  81.         StarApproach(&(thetank->state),ThisLevel.tk[tanktype].color);
  82.         ActiveTankers++;
  83.         ActiveTypes[tanktype]++;
  84.     }
  85. }
  86.  
  87. /*
  88. >>    This routine is called for each active tanker.
  89. >>    An active tanker has gone through the star
  90. >>    phase and now rotates and climbs up.
  91. */
  92. void        UpdateActiveTanker(thetank)
  93. register
  94. Tanker    *thetank;
  95. {
  96.     register    int        dx,dy,x,y;
  97.     register    int        split=0;
  98.     register    int        zap;
  99.     
  100.     thetank->level.f-=ThisLevel.tk[thetank->tanktype].speed;    /*    Move up.    */
  101.     if(thetank->level.i<=0)                /*    Don't move past the top.            */
  102.     {    thetank->level.i=0;
  103.         Hero.lanestat[thetank->lane] |= FlipMask;
  104.         split=1;
  105.     }
  106.     else
  107.     {    /*    Calculate the position and width of the tanker.                            */
  108.         x=ww.x[thetank->lane][thetank->level.i];    /*    Find position on screen.    */
  109.         y=ww.y[thetank->lane][thetank->level.i];
  110.     
  111.         dx=ww.x[thetank->lane+1][thetank->level.i]-x;    /*    Calculate size.            */
  112.         dy=ww.y[thetank->lane+1][thetank->level.i]-y;
  113.     
  114.         if(!VA.Late)                /*    Is there time to draw something?    */
  115.         {    DrawTanker(x,y,dx,dy,thetank->tanktype);
  116.         }
  117.         
  118.         /*    Test to see if the player has hit us.                            */
  119.         if(zap = ShotHitTest(thetank->lane,thetank->level.i)) /* mz */
  120.         {    PlayB(Zroom,11);
  121.             IncreaseScore(ThisLevel.tk[thetank->tanktype].points);
  122.             if (zap != -2)
  123.                 split=1;            /* mz */
  124.             else
  125.             {
  126.                 ThisLevel.totalCount--;
  127.                 thetank->state=inactive;
  128.                 ActiveTankers--;
  129.                 ActiveTypes[thetank->tanktype]--;
  130.                 ThisLevel.tk[thetank->tanktype].count--;
  131.             }
  132.         }
  133.     }
  134.  
  135.     if(split)
  136.     {    
  137.         ThisLevel.tk[thetank->tanktype].count--;
  138.         switch(thetank->tanktype)
  139.         {    case FlipTank:
  140.                 ThisLevel.flCount+=2;
  141.                 CreateSplitFlippers(thetank->lane,thetank->level.i);
  142.                 break;
  143.             case FuseTank:
  144.                 ThisLevel.fuCount+=2;
  145.                 CreateSplitFuseBalls(thetank->lane,thetank->level.i);
  146.                 break;
  147.             case PulsTank:
  148.                 ThisLevel.puCount+=2;
  149.                 CreateSplitPulsars(thetank->lane,thetank->level.i);
  150.                 break;
  151.         }
  152.         ThisLevel.totalCount++;
  153.         thetank->state=inactive;
  154.         ActiveTankers--;
  155.         ActiveTypes[thetank->tanktype]--;
  156.     }
  157. }
  158. /*
  159. >>    Go through the tankers checking their state and
  160. >>    promoting them from stars to fully grown tanker,
  161. >>    when they reach the playfield.
  162. */
  163. void UpdateTankers()
  164. {
  165.     register    Tanker        *tank;
  166.     register    int            i;
  167.     
  168.     tank=Tankers;
  169.     for(i=0;i<MAXTANKERS;i++)
  170.     {    if(tank->state<0)
  171.         {    tank->lane= -(tank->state + 1)/STARDIVISION;
  172.             tank->state= active;
  173.             if(ww.wraps)
  174.             {    if(tank->lane>=ww.numsegs)
  175.                     tank->lane=ww.numsegs-1;
  176.             }
  177.             else
  178.             {    if(tank->lane>ww.numsegs-2)
  179.                     tank->lane=ww.numsegs-2;
  180.                 else
  181.                 if(tank->lane<=0)
  182.                     tank->lane=1;
  183.             }
  184.         }
  185.         else
  186.         {    if(tank->state==active)
  187.                 UpdateActiveTanker(tank);
  188.         }
  189.         tank++;
  190.     }
  191.     
  192.     /* this code should also be activated by the re-descent of a Spiker (mz) */
  193.     /* add condition TankerPermission? (mz) */
  194.     for(i=0;i<TANKTYPES;i++)
  195.     {    if(ActiveTankers<MAXTANKERS && ThisLevel.tk[i].count>ActiveTypes[i])
  196.         {    if(VAPosRandom() < ThisLevel.tk[i].prob+ThisLevel.probIncrease)
  197.             {    CreateNewTanker(i);
  198.             }
  199.         }
  200.         ThisLevel.starCount += ThisLevel.tk[i].count-ActiveTypes[i];
  201.         ThisLevel.activeCount += ActiveTypes[i];
  202.  
  203.     }
  204. }
  205.  
  206. void InitTankers()
  207. {
  208.     register    int        i;
  209.     
  210.     for(i=0;i<MAXTANKERS;i++)
  211.     {    Tankers[i].state=inactive;
  212.     }
  213.     ActiveTankers=0;
  214.     for(i=0;i<TANKTYPES;i++)
  215.     {    ActiveTypes[i]=0;
  216.     }
  217. }
  218.  
  219. void AllocTankers()
  220. {
  221.     Tankers=(Tanker *)NewPtr(sizeof(Tanker)*MAXTANKERS);
  222. }
  223.